package com.sugar.subscribe.course.module.business.controller.app.coachplan;

import com.sugar.subscribe.course.framework.apilog.core.annotation.ApiAccessLog;
import com.sugar.subscribe.course.framework.common.pojo.CommonResult;
import com.sugar.subscribe.course.framework.common.pojo.PageParam;
import com.sugar.subscribe.course.framework.common.pojo.PageResult;
import com.sugar.subscribe.course.framework.common.util.object.BeanUtils;
import com.sugar.subscribe.course.framework.excel.core.util.ExcelUtils;
import com.sugar.subscribe.course.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.subscribe.course.module.business.controller.admin.coachplan.vo.CoachPlanPageReqVO;
import com.sugar.subscribe.course.module.business.controller.admin.coachplan.vo.CoachPlanRespVO;
import com.sugar.subscribe.course.module.business.controller.app.coachplan.vo.AppCoachPlanRespVO;
import com.sugar.subscribe.course.module.business.controller.app.coachplan.vo.AppCoachPlanSaveReqVO;
import com.sugar.subscribe.course.module.business.controller.app.serviceclass.vo.AppServiceClassRespVO;
import com.sugar.subscribe.course.module.business.dal.dataobject.coachplan.CoachPlanDO;
import com.sugar.subscribe.course.module.business.service.coach.CoachService;
import com.sugar.subscribe.course.module.business.service.coachplan.CoachPlanService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static com.sugar.subscribe.course.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.sugar.subscribe.course.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 教练课程方案")
@RestController
@RequestMapping("/biz/coach-plan")
@Validated
public class AppCoachPlanController {

    @Resource
    private CoachPlanService coachPlanService;
    @Resource
    private CoachService coachService;

    @PostMapping("/create")
    @Operation(summary = "教练端 - 创建教练课程方案")
    public CommonResult<Long> createCoachPlan(@Valid @RequestBody AppCoachPlanSaveReqVO createReqVO) {
        createReqVO.setId(null);
        return success(coachPlanService.appCreateCoachPlan(createReqVO, SecurityFrameworkUtils.getLoginUserId(true)));
    }

    @PostMapping("/update")
    @Operation(summary = "教练端 - 更新教练课程方案")
    public CommonResult<Boolean> updateCoachPlan(@Valid @RequestBody AppCoachPlanSaveReqVO updateReqVO) {
        coachPlanService.appUpdateCoachPlan(updateReqVO, SecurityFrameworkUtils.getLoginUserId(true));
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "教练端 - 删除教练课程方案")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCoachPlan(@RequestParam("id") Long id) {
        coachPlanService.deleteCoachPlan(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "教练端 - 获得教练课程方案")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppCoachPlanRespVO> getCoachPlan(@RequestParam("id") Long id) {
        return success(coachPlanService.appGetCoachPlan(id, SecurityFrameworkUtils.getLoginUserId(true)));
    }

    @GetMapping("/page")
    @Operation(summary = "教练端 - 获得教练课程方案分页")
    public CommonResult<PageResult<AppCoachPlanRespVO>> getCoachPlanPage(@Valid PageParam pageParam) {
        return success(coachPlanService.appGetCoachPlanPage(pageParam, SecurityFrameworkUtils.getLoginUserId(true)));
    }
}